package com.en.utils;

import cn.hutool.crypto.digest.DigestUtil;
import com.en.config.GlobalConfig;
import com.en.config.VoiceConfig;
import com.microsoft.cognitiveservices.speech.AudioDataStream;
import com.microsoft.cognitiveservices.speech.SpeechSynthesisResult;

/**
 * ClassName: tts
 * Package: com.en.utils
 * Description:
 *
 * @Date: 2024/1/18 21:37
 * @Author: wht
 */
public class TTS {


    public static String wordEnToSpeechUs(String word) {
        String path = Tools.getWordFullPath(GlobalConfig.speechWordUsRootPath, word);

        SpeechSynthesisResult speechSynthesisResult = VoiceConfig.synthesizerUSJennyNeural.SpeakText(word);
        AudioDataStream stream = AudioDataStream.fromResult(speechSynthesisResult);
        stream.saveToWavFile(path);

        return path.replace("/app/nginx/www", GlobalConfig.nginxRootPath);
    }

//    public static String wordEnToSpeechUk(String word) {
//        String subPath = Tools.getWordSubPath(GlobalConfig.speechWordUkRootPath, word);
//        String outputFilePath = GlobalConfig.speechWordUkRootPath + subPath + "/" + word + ".wav";
//        SpeechSynthesisResult speechSynthesisResult = VoiceConfig.synthesizerUSJennyNeural.SpeakText(word);
//        AudioDataStream stream = AudioDataStream.fromResult(speechSynthesisResult);
//        stream.saveToWavFile(outputFilePath);
//
//        return outputFilePath.replace("/app/nginx/www/", GlobalConfig.nginxRootPath);
//    }


    public static String chineseToSpeech(String translate) {
        String path = Tools.getZhFullPath(GlobalConfig.speechWordZhRootPath, translate);

        SpeechSynthesisResult speechSynthesisResult = VoiceConfig.synthesizerZHXiaoxiaoNeural.SpeakText(translate);
        AudioDataStream stream = AudioDataStream.fromResult(speechSynthesisResult);
        stream.saveToWavFile(path);

        return path.replace("/app/nginx/www", GlobalConfig.nginxRootPath);
    }

}
